package com.hangzhou.welbeing.welbeinginstrument.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
import com.google.gson.Gson;
import com.hangzhou.welbeing.welbeinginstrument.R;
import com.hangzhou.welbeing.welbeinginstrument.adapter.ReleaseHotAdapter;
import com.hangzhou.welbeing.welbeinginstrument.adapter.ReleaseTrueCicleAdapter;
import com.hangzhou.welbeing.welbeinginstrument.base.MyApplication;
import com.hangzhou.welbeing.welbeinginstrument.bean.AddCircleBean;
import com.hangzhou.welbeing.welbeinginstrument.bean.AttentionPostBean;
import com.hangzhou.welbeing.welbeinginstrument.bean.CancelAttentionPostBean;
import com.hangzhou.welbeing.welbeinginstrument.bean.EventBusBean;
import com.hangzhou.welbeing.welbeinginstrument.bean.EventRefreshAttentionCicle;
import com.hangzhou.welbeing.welbeinginstrument.bean.EventZanBean;
import com.hangzhou.welbeing.welbeinginstrument.bean.NewPostBean;
import com.hangzhou.welbeing.welbeinginstrument.bean.PraiseBean;
import com.hangzhou.welbeing.welbeinginstrument.bean.deleteOthersBean;
import com.hangzhou.welbeing.welbeinginstrument.config.RBConstants;
import com.hangzhou.welbeing.welbeinginstrument.inteface.OnRecyclerViewItemClickListener;
import com.hangzhou.welbeing.welbeinginstrument.inteface.OnRecyclerViewItemZanListener;
import com.hangzhou.welbeing.welbeinginstrument.tool.GlideCircleTransform;
import com.hangzhou.welbeing.welbeinginstrument.utils.Utils;
import com.jcodecraeer.xrecyclerview.ProgressStyle;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.Callback;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import okhttp3.Call;
import okhttp3.Response;

/**
 * 杭州惟君医疗科技有限公司17
 * Created by 20433 on 2018/1/29
 */

public class ReleaseTrueCicleActivity extends FragmentActivity implements View.OnClickListener {


    private static final String TAG ="ReleaseTrueCicleActivity" ;
    @Bind(R.id.activity_release_true_circle_xRecyclerView)
    XRecyclerView fragmentHotXRecyclerView;
    @Bind(R.id.activity_release_true_circle_floatingActionButton)
    FloatingActionButton floatingActionButton;

    private ReleaseTrueCicleAdapter releaseTrueCicleAdapter;
    private String circle_id;
    private String circle_num;
    private String circle_name;
    private String circle_state;
    private String circle_url;
    private int circle_num_01;
    private int p = 1;
    private  int  p1 = 1;
    private boolean flag = true;
    private  List<NewPostBean.DataBean> mdateBean = new ArrayList<>();
    private  List<NewPostBean.DataBean> mlistBean = new ArrayList<>();
    private  List<NewPostBean.DataBean> mlistdate = new ArrayList<>();  //转换集合
    private ReleaseHotAdapter releaseHortAdapter;
    private ImageView iv_return;
    private ImageView iv_head_portrait;
    private TextView tv_concrete_circle;
    private TextView tv_members;
    private TextView tv_join;
    private RelativeLayout rl_news;
    private TextView tv_news;
    private RelativeLayout rl_hots;
    private TextView tv_hots;
    private int dataIntent = 0;
    private boolean flag_01 = true;
    private int thumbUpNumber;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_release_true_circle);
        ButterKnife.bind(this);
        Utils.setStatusBar(this, false, false);
        Utils.setStatusTextColor(false, this);

        Intent intent = getIntent();
        circle_id = intent.getStringExtra("circle_id");
        circle_num = intent.getStringExtra("circle_num");
        circle_name = intent.getStringExtra("circle_name");
        circle_state = intent.getStringExtra("circle_state");
        circle_url = intent.getStringExtra("circle_url");

        EventBus.getDefault().register(this);

        LinearLayoutManager layoutManager =   new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        fragmentHotXRecyclerView.setLayoutManager(layoutManager);
        fragmentHotXRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
        fragmentHotXRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallRotate);
        fragmentHotXRecyclerView.setArrowImageView(R.mipmap.iconfont_downgrey);
        fragmentHotXRecyclerView.setPullRefreshEnabled(false);  //TODO 禁止下拉刷新完毕
        fragmentHotXRecyclerView.getDefaultFootView().setNoMoreHint("就这么多了");
        View header = LayoutInflater.from(this).inflate(R.layout.fragment_release_true_cicle_header, (ViewGroup)findViewById(android.R.id.content),false);
        findHeaderView(header);
        fragmentHotXRecyclerView.addHeaderView(header);
        fragmentHotXRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                if(dataIntent == 0 ){ //最新
                    flag_01 = true;
                    loadNewPostDate(p1);
                }else if(dataIntent == 1){ //最热
                    flag = true;
                    loadReleaseHotDate(p);
                }
            }

            @Override
            public void onLoadMore() {
                if(dataIntent == 0 ){ //最新
                    p1++;
                    flag_01 = false;
                    loadNewPostDate(p1);

                }else if(dataIntent == 1){ //最热
                    p++;
                    flag = false;
                    loadReleaseHotDate(p);

                }
            }
        });
        releaseHortAdapter = new ReleaseHotAdapter(this); // TODO 传入数据  有问题 cus_name null  cus_logo null
        fragmentHotXRecyclerView.setAdapter(releaseHortAdapter);
        //fragmentHotXRecyclerView.refresh();
        releaseHortAdapter.setOnItemClickListener(new OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view) { // TODO 点击进入详情页
                int postion = fragmentHotXRecyclerView.getChildAdapterPosition(view)-2;
                NewPostBean.DataBean datalist = mlistdate.get(postion);
                if(datalist != null ){
                    Intent intent = new Intent(ReleaseTrueCicleActivity.this, ReleaseSimilarProfilePageFocusedActivity.class);
                    intent.putExtra("posts_deleted", "ReleaseTrueCicleActivity");
                    intent.putExtra("posts_deleted_id", postion);


                    intent.putExtra("po_id", datalist.po_id);
                    intent.putExtra("po_name", datalist.po_name);
                    intent.putExtra("addtime", datalist.addtime);
                    intent.putExtra("video", datalist.video);
                    intent.putExtra("vpic", datalist.vpic);
                    intent.putExtra("content", datalist.content);
                    intent.putExtra("cat_id", datalist.cat_id);
                    intent.putExtra("cus_id", datalist.cus_id);
                    intent.putExtra("cus_name", datalist.cus_name);
                    intent.putExtra("cus_logo", datalist.cus_logo);
                    intent.putExtra("hits_like", datalist.hits_like);
                    intent.putExtra("lstate", datalist.lstate);
                    intent.putExtra("col", datalist.col);
                    intent.putExtra("state", datalist.state);
                    intent.putExtra("count", datalist.count);
                    intent.putExtra("lCount", datalist.lCount);
                    intent.putExtra("po_url", (Serializable) datalist.po_url);
                    startActivity(intent);
                }
            }

            @Override
            public void onItemFirstButtonClick(View v, int position) {  //TODO 点击 跳转关注
                TextView textView= (TextView) v;
                String str = textView.getText().toString().trim();
                String attention_id = mlistdate.get(position).cus_id;
                if(str.equals("关注")){  //todo 调用关注的方法
                    addAttentionPost(textView,attention_id);
                }else if(str.equals("已关注")){  //todo 调用取消关注的方法
                    cancelAttentionPost(textView,attention_id);
                }
            }
        });
        releaseHortAdapter.setmOnItemZanClickListener(new OnRecyclerViewItemZanListener() {
            @Override
            public void onItemZanClick(View v, int position, View view) {
                ImageView imageView= (ImageView) v;
                TextView textView= (TextView) view;
                String cat_id_01 =  mlistdate.get(position).cat_id;
                String po_id_01 =  mlistdate.get(position).po_id;
                String thumbUp = textView.getText().toString().trim();
                try {
                    thumbUpNumber = Integer.parseInt(thumbUp);
                    giveLike(cat_id_01,imageView,po_id_01,textView,position);
                } catch (NumberFormatException e) {
                }
            }
        });

        loadNewPostDate(p1);
    }

    /**
     * @desc 查找控件
     * */
    private void findHeaderView(View header) {
        iv_return = (ImageView) header.findViewById(R.id.fragment_release_true_cicle_header_iv_return);
        iv_head_portrait = (ImageView) header.findViewById(R.id.fragment_release_true_cicle_header_iv_head_portrait);
        tv_concrete_circle = (TextView) header.findViewById(R.id.fragment_release_true_cicle_header_tv_concrete_circle);
        tv_members = (TextView) header.findViewById(R.id.fragment_release_true_cicle_header_tv_members);
        tv_join = (TextView) header.findViewById(R.id.fragment_release_true_cicle_header_tv_join);

        rl_news = (RelativeLayout) header.findViewById(R.id.fragment_release_true_cicle_header_rl_news);
        tv_news = (TextView) header.findViewById(R.id.fragment_release_true_cicle_header_tv_news);


        rl_hots = (RelativeLayout) header.findViewById(R.id.fragment_release_true_cicle_header_rl_hots);
        tv_hots = (TextView) header.findViewById(R.id.fragment_release_true_cicle_header_tv_hots);

        iv_return.setOnClickListener(this);
        tv_join.setOnClickListener(this);
        rl_news.setOnClickListener(this);
        rl_hots.setOnClickListener(this);
        floatingActionButton.setOnClickListener(this);
        if(circle_id == null  && TextUtils.isEmpty(circle_id)){
            finish();
            overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
        }else{
            if(circle_id.equals("0")){
                tv_join.setText("加入");
            }else if(circle_id.equals("1")){
                tv_join.setText("退出");
            }
        }
        try {
            circle_num_01 = Integer.parseInt(circle_num);
            if(circle_num_01 >= 0){
                tv_members.setText(circle_num);
            }else{
                tv_members.setText("0");
            }
        } catch (NumberFormatException e) {
        }
        tv_concrete_circle.setText(circle_name);
        Glide.with(this).load("http://oop.welbeing.cn/Public/Uploads/" + circle_url).transform(new BitmapTransformation[] { new GlideCircleTransform(this) }).placeholder(R.mipmap.head_portrait).error(R.mipmap.head_portrait).crossFade().into(iv_head_portrait);


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.fragment_release_true_circle_header_01_iv_return:
                finish();
                overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
                break;
            case R.id.fragment_release_true_circle_header_01_tv_join: // TODO 加入圈子
                String textjoin =  tv_join.getText().toString().trim();
                if(textjoin.equals("加入")){
                    addCircle(circle_id);
                }else if(textjoin.equals("退出")){
                    cancel(circle_id);
                }
                break;
            case R.id.activity_release_true_circle_floatingActionButton: // TODO 跳转到编辑页面
                Intent intent = new Intent(ReleaseTrueCicleActivity.this, ReleaseEditingActivity.class);
                intent.putExtra("circle_id",circle_id);
                intent.putExtra("circle_name",circle_name);
                startActivity(intent);
                overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
                break;
            case R.id.fragment_release_true_cicle_header_rl_news: //最新
                tv_news.setTextColor(0xffffb3b3);
                tv_hots.setTextColor(0xff323232);
                releaseHortAdapter.notifyDataSetChanged();
                dataIntent = 0;
                mlistBean.clear();
                mdateBean.clear();
                mlistdate.clear();
                p1 = 1;
                loadNewPostDate(p1);
                break;
            case R.id.fragment_release_true_cicle_header_rl_hots: //最热
                tv_news.setTextColor(0xff323232);
                tv_hots.setTextColor(0xffffb3b3);
                loadReleaseHotDate(p);
                releaseHortAdapter.notifyDataSetChanged();
                dataIntent = 1;
                mlistBean.clear();
                mdateBean.clear();
                mlistdate.clear();
                p= 1;
                loadReleaseHotDate(p);
                break;

        }
    }
    /**
     * @desc 推出圈子
     * */
    private void cancel(String circle_id) {
        SharedPreferences sp = getSharedPreferences("second_app_internal_data", 0);
        String user_id = sp.getString("user_id","");
        OkHttpUtils
                .post()
                .url(RBConstants.SERVER_URL+RBConstants.CANCEL_JOIN)
                .addParams("cus_id",user_id)
                .addParams("cat_id", circle_id)
                .build()
                .execute(new Callback() {
                    @Override
                    public Object parseNetworkResponse(Response response, int id) throws Exception {
                        String parseNetworkResponse = response.body().string();
                        Gson gson =  new Gson();
                       //Log.e("tag","parseNetworkResponse===7777====="+parseNetworkResponse);
                        final AddCircleBean addCircleBean =  gson.fromJson(parseNetworkResponse, AddCircleBean.class);
                        MyApplication.getmHandler().post(new Runnable() {
                            @Override
                            public void run() {
                                if(addCircleBean.errorCode == 200){
                                    circle_num_01 = circle_num_01-1;
                                    tv_members.setText(circle_num_01+"");
                                    tv_join.setText("加入");
                                }else{
                                    Toast.makeText(ReleaseTrueCicleActivity.this, addCircleBean.errorMessage, Toast.LENGTH_SHORT).show();
                                }
                            }
                        });
                        return null;
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Toast.makeText(ReleaseTrueCicleActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onResponse(Object response, int id) {

                    }
                });
    }

    /**
     * @desc 加入圈子
     * */
    private void addCircle(String circle_id) {
        SharedPreferences sp = getSharedPreferences("second_app_internal_data", 0);
        String user_id = sp.getString("user_id","");
        OkHttpUtils
                .post()
                .url(RBConstants.SERVER_URL+RBConstants.ADD_CIRCLE)
                .addParams("cus_id",user_id)
                .addParams("cat_id", circle_id)
                .build()
                .execute(new Callback() {
                    @Override
                    public Object parseNetworkResponse(Response response, int id) throws Exception {
                        String parseNetworkResponse = response.body().string();
                        Gson gson =  new Gson();
                        //Log.e("tag","parseNetworkResponse===88888====="+parseNetworkResponse);
                        final AddCircleBean addCircleBean =  gson.fromJson(parseNetworkResponse, AddCircleBean.class);
                        MyApplication.getmHandler().post(new Runnable() {
                            @Override
                            public void run() {
                                if(addCircleBean.errorCode == 200){
                                    circle_num_01 =circle_num_01+1;
                                    tv_members.setText(circle_num_01+"");
                                    tv_join.setText("退出");
                                }else{
                                    Toast.makeText(ReleaseTrueCicleActivity.this, addCircleBean.errorMessage, Toast.LENGTH_SHORT).show();
                                }
                            }
                        });
                        return null;
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {

                    }

                    @Override
                    public void onResponse(Object response, int id) {

                    }
                });
    }

    /**
     * @desc 加载最热数据
     * */
    private void loadReleaseHotDate(int p) {
        SharedPreferences sp = getSharedPreferences("second_app_internal_data", 0);
        String user_id = sp.getString("user_id","");
        OkHttpUtils
                .post()
                .url(RBConstants.SERVER_URL+RBConstants.NEW_HOSTS)
                .addParams("cat_id",circle_id)
                .addParams("cus_id", user_id)
                .addParams("p", p+"")
                .build()
                .execute(new Callback() {
                    @Override
                    public Object parseNetworkResponse(Response response, int id) throws Exception {
                        String parseNetworkResponse = response.body().string();
                        Gson gson =  new Gson();
                        //Log.e("tag","parseNetworkResponse===%%%%%====="+parseNetworkResponse);
                        final NewPostBean newPostBean =  gson.fromJson(parseNetworkResponse, NewPostBean.class);
                        MyApplication.getmHandler().post(new Runnable() {
                            @Override
                            public void run() {
                                if(newPostBean.errorCode == 200){
                                    List<NewPostBean.DataBean> mlist = newPostBean.data;
                                    if(mlist != null && mlist.size() >0){
                                        //Log.e("tag","parseNetworkResponse===%%%%%=55====");
                                        mdateBean.addAll(mlist);

                                        mlistdate.addAll(mlist);
                                        releaseHortAdapter.addItem(mlistdate);
                                        if(flag){
                                            if(fragmentHotXRecyclerView != null){
                                                fragmentHotXRecyclerView.refreshComplete(); //TODO 下拉刷新完毕
                                            }

                                        }else{
                                            if(fragmentHotXRecyclerView != null){
                                                fragmentHotXRecyclerView.loadMoreComplete();  //TODO 上拉加载完毕
                                            }
                                        }
                                    }else {
                                        if(fragmentHotXRecyclerView != null){
                                            fragmentHotXRecyclerView.setNoMore(true);
                                        }
                                    }
                                    //releaseHortAdapter.notifyDataSetChanged();
                                }else{
                                    Toast.makeText(ReleaseTrueCicleActivity.this,newPostBean.errorMessage,Toast.LENGTH_LONG).show();
                                }
                            }
                        });
                        return null;
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Toast.makeText(ReleaseTrueCicleActivity.this,"网络异常",Toast.LENGTH_LONG).show();
                    }

                    @Override
                    public void onResponse(Object response, int id) {

                    }
                });
    }


    /**
     * @desc 加载最新数据
     * */
    private void loadNewPostDate(int p1) {
        SharedPreferences sp = getSharedPreferences("second_app_internal_data", 0);
        String user_id = sp.getString("user_id","");
        OkHttpUtils
                .post()
                .url(RBConstants.SERVER_URL+RBConstants.NEW_POST)
                .addParams("cat_id",circle_id)
                .addParams("cus_id", user_id)
                .addParams("p", p1+"")
                .build()
                .execute(new Callback() {
                    @Override
                    public Object parseNetworkResponse(Response response, int id) throws Exception {
                        String parseNetworkResponse = response.body().string();
                        Gson gson =  new Gson();
                        Log.e("tag","parseNetworkResponse===####234====="+parseNetworkResponse);
                        final NewPostBean newPostBean =  gson.fromJson(parseNetworkResponse, NewPostBean.class);
                        //Log.e("tag","parseNetworkResponse===####234=====");
                        MyApplication.getmHandler().post(new Runnable() {
                            @Override
                            public void run() {
                            if(newPostBean.errorCode == 200){
                                List<NewPostBean.DataBean> mdate =   newPostBean.data;
                                if(mdate != null  && mdate.size() >0){
                                    mlistBean.addAll(mdate);
                                    mlistdate.addAll(mdate);
                                    releaseHortAdapter.addItem(mlistdate);
                                    if(flag_01){
                                        fragmentHotXRecyclerView.refreshComplete(); //TODO 下拉刷新完毕
                                    }else{
                                        fragmentHotXRecyclerView.loadMoreComplete();  //TODO 上拉加载完毕
                                    }
                                }else{
                                    fragmentHotXRecyclerView.setNoMore(true);
                                }
                                //releaseHortAdapter.notifyDataSetChanged();
                            }else{
                                Toast.makeText(ReleaseTrueCicleActivity.this,newPostBean.errorMessage,Toast.LENGTH_LONG).show();
                            }
                            }
                        });
                        return null;
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Toast.makeText(ReleaseTrueCicleActivity.this,"网络异常",Toast.LENGTH_LONG).show();
                    }

                    @Override
                    public void onResponse(Object response, int id) {

                    }
                });
    }



    /**
     *
     * @desc 关注帖子
     * */
    private void addAttentionPost(final TextView textView, String attention_id) {
        SharedPreferences sp = getSharedPreferences("second_app_internal_data", 0);
        String user_id = sp.getString("user_id","");
        OkHttpUtils
                .post()
                .url(RBConstants.SERVER_URL+RBConstants.ADD_ATTENTION_POST)
                .addParams("cus_id",user_id)
                .addParams("followed", attention_id)
                .build()
                .execute(new Callback() {
                    @Override
                    public Object parseNetworkResponse(Response response, int id) throws Exception {
                        String strresponse = response.body().string();
                        Gson gson = new Gson();
                       // Log.e("tag","+++++loadDate+++=========1234============++++"+strresponse);
                        final AttentionPostBean attentionPostBean =  gson.fromJson(strresponse,AttentionPostBean.class);
                        MyApplication.getmHandler().post(new Runnable() {
                            @Override
                            public void run() {
                                if(attentionPostBean.errorCode == 200){
                                    textView.setText("已关注");
                                    Toast.makeText(ReleaseTrueCicleActivity.this, "关注成功", Toast.LENGTH_SHORT).show();
                                }else{
                                    Toast.makeText(ReleaseTrueCicleActivity.this, attentionPostBean.errorMessage, Toast.LENGTH_SHORT).show();
                                }
                            }
                        });
                        return null;
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Toast.makeText(ReleaseTrueCicleActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onResponse(Object response, int id) {

                    }
                });

    }
    /**
     * @DESC 取消关注的方法
     * */
    private void cancelAttentionPost(final TextView textView, String attention_id) {
        SharedPreferences sp = getSharedPreferences("second_app_internal_data", 0);
        String user_id = sp.getString("user_id","");
        OkHttpUtils
                .post()
                .url(RBConstants.SERVER_URL+RBConstants.CANCLE_ATTENTION_POST)
                .addParams("cus_id", user_id)
                .addParams("followed", attention_id)
                .build()
                .execute(new Callback() {
                    @Override
                    public Object parseNetworkResponse(Response response, int id) throws Exception {
                        String strresponse = response.body().string();
                        Gson gson = new Gson();
                       // Log.e("tag","+++++loadDate+++=========1234============++++"+strresponse);
                        final CancelAttentionPostBean cancelAttentionPostBean =    gson.fromJson(strresponse, CancelAttentionPostBean.class);
                        MyApplication.getmHandler().post(new Runnable() {
                            @Override
                            public void run() {
                                if(cancelAttentionPostBean.errorCode == 200){
                                    textView.setText("关注");
                                    Toast.makeText(ReleaseTrueCicleActivity.this, "取消关注", Toast.LENGTH_SHORT).show();
                                }else{
                                    Toast.makeText(ReleaseTrueCicleActivity.this, cancelAttentionPostBean.errorMessage, Toast.LENGTH_SHORT).show();
                                }
                            }
                        });
                        return null;
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Toast.makeText(ReleaseTrueCicleActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onResponse(Object response, int id) {

                    }
                });
    }




    /**
     * @desc 点赞
     * @param cat_id_01
     * @param imageView
     * @param po_id_01
     * @param textView     */
    private void giveLike(String cat_id_01, final ImageView imageView, String po_id_01, final TextView textView ,final int position) {
        SharedPreferences sp = getSharedPreferences("second_app_internal_data", 0);
        String  user_id = sp.getString("user_id","");
        OkHttpUtils
                .post()
                .url(RBConstants.SERVER_URL+RBConstants.PRAISE)
                .addParams("cus_id", user_id)
                .addParams("cat_id", cat_id_01)
                .addParams("po_id", po_id_01)
                .build()
                .execute(new Callback() {
                    @Override
                    public Object parseNetworkResponse(Response response, int id) throws Exception {
                        String praiseParseNetworkResponse =  response.body().string();
                        Gson gson = new Gson();
                       // Log.e(TAG,"praiseParseNetworkResponse======555======>"+praiseParseNetworkResponse);
                        final PraiseBean praiseBean =  gson.fromJson(praiseParseNetworkResponse,PraiseBean.class);
                        MyApplication.getmHandler().post(new Runnable() {
                            @Override
                            public void run() {
                                if(praiseBean.errorCode == 200){
                                    if(praiseBean.errorMessage.equals("点赞成功!")){
                                        if(thumbUpNumber >= 0){
                                            thumbUpNumber = thumbUpNumber +1;
                                            textView.setText(thumbUpNumber+"");

                                            NewPostBean.DataBean datalist = mlistdate.get(position);
                                            datalist.lstate = 1;
                                            datalist.hits_like = thumbUpNumber;
                                            mlistdate.set(position,datalist);
                                        }

                                        imageView.setImageResource(R.mipmap.zanz_00);
                                        Toast.makeText(ReleaseTrueCicleActivity.this,"点赞成功",Toast.LENGTH_LONG).show();
                                    }else if(praiseBean.errorMessage.equals("点赞取消!")){
                                        if(thumbUpNumber >= 1){
                                            thumbUpNumber = thumbUpNumber - 1;
                                            textView.setText(thumbUpNumber+"");
                                            NewPostBean.DataBean datalist = mlistdate.get(position);
                                            datalist.lstate = 0;
                                            datalist.hits_like = thumbUpNumber;
                                            mlistdate.set(position,datalist);
                                        }
                                        imageView.setImageResource(R.mipmap.zan_90);
                                        Toast.makeText(ReleaseTrueCicleActivity.this,"取消点赞",Toast.LENGTH_LONG).show();
                                    }
                                }else{
                                    Toast.makeText(ReleaseTrueCicleActivity.this,praiseBean.errorMessage,Toast.LENGTH_SHORT).show();
                                }
                            }
                        });
                        return null;
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Toast.makeText(ReleaseTrueCicleActivity.this,"网络异常",Toast.LENGTH_LONG).show();
                    }

                    @Override
                    public void onResponse(Object response, int id) {

                    }
                });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
    @Subscribe
    public void onEventMainThread(EventRefreshAttentionCicle event){
        //接收到发布者发布的事件后，进行相应的处理操作
        if(event.getRefreshAttentionCicle().equals("TrueCicle")){
            tv_news.setTextColor(0xffffb3b3);
            tv_hots.setTextColor(0xff323232);

            dataIntent = 0;
            mlistBean.clear();
            mdateBean.clear();
            mlistdate.clear();
            p1 = 1;
            p = 1;
            releaseHortAdapter.notifyDataSetChanged();
            loadNewPostDate(p1);
        }
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();
        overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
    }
    @Subscribe
    public void onEventMainThread(deleteOthersBean event){
       // Log.e("tag","onEventMainThread==onEventMainThread=####234最新=====");
        //接收到发布者发布的事件后，进行相应的处理操作
        if(event.getDeleteString().equals("ReleaseTrueCicleActivity")){  //调用刷新 接口
            //Log.e("tag","parseNetworkResponse===####234最新=调用刷新====");
            mlistBean.clear();
            mdateBean.clear();
            mlistdate.clear();
            p = 1;
            p1 =1;
            if(dataIntent == 0 ){ //最新
               // Log.e("tag","parseNetworkResponse===####234最新=====");
                loadNewPostDate(p1);
            }else if(dataIntent == 1){  //最热
                //Log.e("tag","parseNetworkResponse===####234最热=====");
                loadReleaseHotDate(p);
            }

        }
    }

    @Subscribe
    public void onEventMainThread(EventBusBean event){
        //接收到发布者发布的事件后，进行相应的处理操作
        if(event.getPosts_deleted().equals("ReleaseTrueCicleActivity")){
            mlistdate.remove(event.getPosts_deleted_id());
            releaseHortAdapter.notifyDataSetChanged();
        }
    }

    @Subscribe
    public void onEventMainThread(EventZanBean event){
        // Log.e(TAG,"praiseParseNetworkResponse=====进行相应的处理操作=555======>");
        //接收到发布者发布的事件后，进行相应的处理操作
        if(event.getIdentifier().equals("ReleaseTrueCicleActivity")){
            // Log.e(TAG,"praiseParseNetworkResponse=====进行相应的处理操作=releaseFindFragment======>");
            NewPostBean.DataBean datalist =   mlistdate.get(event.getPostion());
            datalist.hits_like = event.getHits_like();
            datalist.lstate = event.getLstate1();
            mlistdate.set(event.getPostion(),datalist);
            releaseHortAdapter.notifyDataSetChanged();
        }
    }
}
